# -*- coding: utf-8 -*-

from core.viewset import CustomModelViewSet
from rest_framework import permissions 
from .models import OnlineDocument
from .serializers import *
from .resources import *
from .filters import *


class IsOwnerOrReadOnly(permissions.BasePermission): 
    def has_object_permission(self, request, view, obj): 
        if request.method  in permissions.SAFE_METHODS: 
            return True 
        return obj.user  == request.user

class OnlineDocumentViewSet(CustomModelViewSet):
    """
    在线文档接口
    list:查询
    create:新增
    update:修改
    retrieve:单例
    destroy:删除
    """

    queryset = OnlineDocument.objects.all()
    serializer_class = OnlineDocumentSerializer
    filterset_class = OnlineDocumentFilterSet
    import_resources = OnlineDocumentResouces
    export_resources = OnlineDocumentResouces
    permission_classes = [permissions.IsAuthenticated, IsOwnerOrReadOnly]
